<?php
namespace app\user\controller;
use think\Controller;
use think\facade\Request;
use think\captcha\Captcha;
class Titles extends Controller{
    protected $sys;
    public function initialize(){
        $this->sys = cache('System');
        $this->assign('sys',$this->sys);
    }
    public function index(){
            $table = db('users');
            $users = $table->where('id','gt', 0)->limit(0,100)->select();
            $users = $table->where('id','gt', 0)->limit(100,100)->select();
            $users = $table->where('id','gt', 0)->limit(200,100)->select();
            $users = $table->where('id','gt', 0)->limit(300,100)->select();
            $titles=$this->sys['titles'];
            $nowtime=time();
            foreach ($users as $key => $value) {
                $left=db('users')->where('id',$value['leftid'])->find();
                if(!empty($left)){
                    $ppath1=$left['ppath'].$left['id'];
                    $count1=db('users')
                        ->where('ppath','like','%'.$ppath1.'%')
                        ->count();
                    $count11=$count1+1;
                }else{
                    $count11=0;
                }
                $right=db('users')->where('id',$value['rightid'])->find();
                if(!empty($right)){
                    $ppath2=$right['ppath'].$right['id'];
                    $count2=db('users')
                        ->where('ppath','like','%'.$ppath2.'%')
                        ->count();
                    $count22=$count2+1;
                }else{
                    $count22=0;
                }


                $array=array(
                    'area1'=>$count11,
                    'area2'=>$count22,
                );
                db('users')->where('id',$value['id'])->update($array);



         /*       $endtime=$value['reg_time']+86400*$titles;
                if($endtime<$nowtime){
                    db('users')->where('id',$value['id'])->setField('isclose',2);
                }*/
            }
            echo "成功";
    }
}